var express = require('express');
var router = express.Router();
//引入jwt的工具类
const {createJwt} = require("../src/utils/jwtUtil")
//引入业务层
const userService = require('../src/services/user/userServices')

/* GET users listing. */
router.post('/login', async function(req, resp, next) {
    //获得客户端的参数
    let {username,pwd} = req.body;
    let data =  await userService.login(username,pwd);
    console.log(data,"====>>")
    if(data!=null){
      //如果登录成功则创建一个jwt
      let jwt = createJwt({"username":username,"loginTime":new Date()});
      resp.json({"code":1,"msg":"登录成功","_t":`Bearer ${jwt}`});
    }else{
      resp.json({"code":0,"msg":"用户名或者密码错误"})
    }
});

module.exports = router;
